package com.yifan.xmlTool.interfaces;

import org.dom4j.Document;
import org.dom4j.Element;

import java.lang.reflect.Field;
import java.util.*;

/**
 * @Author YIFan
 * @Date 2021/3/2 10:34
 * @Version 1.0
 */
public class XMLObj {
    // 超类
    public Object obj;
    public Document gen = null;
    public Class<?> model = null;
    // 根元素
    public Element root = null;
    // 所有元素
    public List<Element> elements = new ArrayList<>();
    // 所有字段
    public List<Field> fields = new ArrayList<>();
    // 所有属性
    public Map<String, String> attributes = new HashMap<>();

    public XMLObj(){}
    public XMLObj(Object c){
        obj = c;
        model = c.getClass();
        Class<?> aClass = model;
        while (!(aClass == Object.class)) {
            // 获取c类中所有声明的字段
            fields.addAll(Arrays.asList(aClass.getDeclaredFields()));
            aClass = aClass.getSuperclass();
        }
    }

}
